import React from "react";
import { IconFont } from "@knowdesign/icons";
// import { message } from "knowdesign";
import { message } from "antd";
import { ArgsProps, ConfigOnClose } from "knowdesign/es/basic/message";

type ConfigContent = React.ReactNode;
type ConfigDuration = number | (() => void);
type JointContent = ConfigContent | ArgsProps;

message.config({
  top: 16,
});

function isArgsProps(content: JointContent): content is ArgsProps {
  return (
    Object.prototype.toString.call(content) === "[object Object]" &&
    !!(content as ArgsProps).content
  );
}

function isEmptyObject(obj) {
  return obj && typeof obj === "object" && Object.keys(obj).length === 0;
}

// const openMessage = (
//   type: "info" | "success" | "warning" | "error",
//   content: JointContent,
//   duration?: ConfigDuration,
//   onClose?: ConfigOnClose
// ) => {
//   if (isArgsProps(content)) {
//     message &&
//       message[type]({
//         icon: <IconFont type={`icon-${type}-circle`} />,
//         ...content,
//       });
//   } else {

//     message[type]({
//       icon: <IconFont type={`icon-${type}-circle`} />,
//       content,
//       duration,
//       onClose,
//     });
//   }
// };

const customMessage = {
  info(
    content: JointContent,
    duration?: ConfigDuration,
    onClose?: ConfigOnClose
  ) {
    message.info(content);
  },
  success(
    content: JointContent,
    duration?: ConfigDuration,
    onClose?: ConfigOnClose
  ) {
    message.success(content);
  },
  warning(
    content: JointContent,
    duration?: ConfigDuration,
    onClose?: ConfigOnClose
  ) {
    message.warning(content);
  },
  error(
    content: JointContent,
    duration?: ConfigDuration,
    onClose?: ConfigOnClose
  ) {
    message.error(content);
  },
};

export default customMessage;
